
clear all
/*insert directory here*/

use persinccty69-2021, clear
drop if year>2019
gen factor=.
forvalues y=2000/2019{
replace factor=persinc if year==`y'
egen max`y'=max(factor), by(statefip ctyfip)
replace factor=.
gen ratio`y'=persinc/max`y'
}
drop persinc factor
reshape long ratio max, i(statefip ctyfip year) j(censusyear)
drop max
rename year furnyear
merge 1:m censusyear furnyear statefip ctyfip using puma2ctyfurn
keep if _merge==3
drop _merge ctyfip
drop if censusyear-furnyear>17
rename ratio incfactorfurn
save incfactorfurn2019, replace
drop if censusyear==furnyear>10
rename furnyear wateryear
rename incfactorfurn incfactorwater
save incfactorwater2019, replace

use persinccty69-2021, clear
gen factor=.
replace factor=persinc if year==2000
egen max2000=max(factor), by(statefip ctyfip)
replace factor=.
gen incadj2000=persinc/max2000
replace factor=persinc if year==2006
egen max2006=max(factor), by(statefip ctyfip)
gen incadj2006=persinc/max2006
keep if year>2000 & year<2006
drop if statefip==2 | statefip==15
keep statefip ctyfip year incadj2000 incadj2006
merge 1:m year statefip ctyfip using puma2cty
keep if _merge==3
drop _merge ctyfip
reshape long incadj, i(statefip geoid year) j(censusyear)
save incadj01-05, replace